#!/usr/bin/perl -w
#

use Switch;

# Config
my $cfg;
my $os="lin";
(-e "C:\\") && ($os="win");

defined( $ARGV[0]) and ($cfg=$ARGV[0]); 
if( $os eq "win" ){
    defined( $ARGV[0]) or ($cfg="./hyrepo.conf");
}else{
    defined( $ARGV[0]) or ($cfg="/etc/hyrepo.conf");
}

# parse configuration file to get repo info
open FILE,"$cfg";
defined(FILE) or die "Fail to open config file $cfg\n";
foreach ( <FILE>){
    $_=~/(\S+)\s+(\S+)/ && !($_=~/^\#/) && update($1,$2);
}
close FILE;

# Actual updating action to the repositories.
sub update{
    my ($type, $path)=@_;
    print "[Updating $type repo $path]\n";
    switch( $type){
        case "git-svn" { 
            chdir $path;
            system( "git gc"); 
        }
        case "git" {
            chdir $path;
            system( "git gc");
        }
    }
}

